'''
Created on Jan 29, 2010

@author: christianp
'''
import threading
from BruTile.Web.ImageRequest import ImageRequest

class FetchOnThread(threading.Thread):
    
    super_doAfter = None
    tile_info = None
    __queue = None
    __image_request = ImageRequest()
    
    def __init__(self, key, queue):
        threading.Thread.__init__(self, name=str(key))
        self.__queue = queue
    
    def run(self):
        request = self.__queue.get()
        self.super_do_after, url, self.tile_info = request
        self.__image_request.getImageFromServer(url, self.doAfter)

    def doAfter(self, bitmap, duration):
        self.tile_info.fetchingTime = duration
        self.super_do_after(self.tile_info, bitmap)